/**
 * Created by liuzengrong on 2019/8/16.
 */
import React from 'react';
import { connect } from 'dva';
import StandardModule from '@/components/hyperspace/modules/StandardModule';
import DeclareInfoWord from './components/DeclareInfoWord';


let declareInfoWord: any = {};

/**
 * 自定义模块
 */
// @ts-ignore
const LocalModule: React.FC = ({ customsWord, dispatch }) => (
  <div>
    <StandardModule
      data={customsWord.data}
      dictionary={[
        {
          name: 'workNo',
          desc: '报关工作单号',
          dataType: 'string',
        },
        {
          name: 'loadingPort',
          desc: '出货港口',
          dataType: 'string',
        },
      ]}
      config={{
        common: {
          formItemOptions: {
            username: {
              rules: [{ required: true, message: '该字段不能为空！' }],
            },
          },
        },
        search: {
          fields: ['serviceNo', 'workNo', 'customerName', 'loadingPort'], // 查询条件
          tabs: {
            field: 'status',
            tabItems: [
              {
                title: '全部',
                value: '',
                active: true,
              },
              {
                title: '待审核',
                value: 'TO_AUDIT',
              },
              {
                title: '审核通过',
                value: 'AUDIT_PASS',
              },
              {
                title: '审核失败',
                value: 'AUDIT_FAIL',
              },
              {
                title: '已上架',
                value: 'ONLINE',
              },
              {
                title: '已下架',
                value: 'OFFLINE',
              },
            ],
          },
        },
        list: {
          url: '/api/customsWord/query',
          fields: [
            'id',
            'serviceNo',
            'workNo',
            'goodsName',
            'customerName',
            'loadingPort',
            'total',
            'status',
            'creator',
            'creatTime',

          ], // 列表字段
          format: {
            username: {
              render: (value: any) => `格式化 - ${value}`,
            },
          },
          extensions: {
            operations: [
              (record: any) => (
                <a
                  onClick={() => {
                    if (declareInfoWord) declareInfoWord.handleOpen();
                  }}
                >
                  跟单
                </a>
              ),
            ],
          },
        },
        delete: {
          url: '/api/customsWord/remove',
          batchDeleteUrl: '', // 批量删除URL
          batchDelete: false, // 是否开启批量删除
          fields: ['id'], // 删除依据字段
        },
      }}
      namespace="customsWord"
      dispatch={dispatch}
    />
    {/* eslint-disable-next-line no-return-assign */}
    <DeclareInfoWord wrappedComponentRef={(inst: any) => (declareInfoWord = inst)}
      {...declareInfoWord}
      visible
    />
  </div>
);

// @ts-ignore
export default connect(({ customsWord }) => ({
  customsWord,
}))(LocalModule);
